<template>
	<view class="c-item">
		<view class="wrapper" @click="handleClick">
			<view class="left">
				<image class="avatar" src="~@/static/img/device.png" mode=""></image>
			</view>
			<view class="center">
				<view class="top">
					{{data.name}}
				</view>
				<view class="bottom">
					{{data.id}}
				</view>
			</view>
			<view class="right">
				<view class="top">
					rssi: {{data.rssi}}
				</view>
				<view class="bottom">
					<view v-if="data.status===1">
						<image class="status" src="~@/static/img/device/connected.png" mode=""></image>
					</view>
					<view v-else>
						<image class="status" src="~@/static/img/device/not-connected.png" mode=""></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "c-item",
		props: {
			data: {
				type: Object,
				required: true
			}
		},
		methods: {
			handleClick() {
				this.$emit('click', this.data);
			}
		}
	}
</script>

<style lang="scss">
	.c-item {
		padding: 10rpx 0;
		cursor: pointer;

		.wrapper {
			display: flex;
			justify-content: space-around;
			align-items: center;
			padding-bottom: 10rpx;
			border-bottom: solid 1px $uni-border-color;

			.left {
				.avatar {
					width: 100rpx;
					height: 80rpx;
					padding: 10rpx 10rpx 10rpx 10rpx;
				}
			}

			.center {
				flex: 1;
				display: flex;
				flex-direction: column;
				padding: 0 20rpx;

				.top {
					font-size: 30rpx;
					font-weight: bold;
					padding: 10rpx 0 18rpx 0;
				}

				.bottom {
					color: $uni-text-color-grey;
					padding-bottom: 10rpx;
				}
			}

			.right {
				display: flex;
				flex-direction: column;
				align-items: center;

				.top {
					color: $uni-text-color-grey;
					padding: 10rpx 0 18rpx 0;
				}

				.bottom {
					padding-bottom: 10rpx;
					
					.status {
						width: 40rpx;
						height: 40rpx;
					}
				}
			}
			
			&:active {
				background-color: #41434D;
				transition: all 0s;
			}
		}
	}
</style>
